using UnityEngine;
using System.Collections;

public class Tiro_Game : MonoBehaviour
{
    GameObject alvo;
    GameObject player;
    GameObject mao;

    GUIStyle TextStyle;

    AudioSource audio_s;
    AudioClip audio_c;

    int pontos;
    public static int win;
    public static bool colidindo = false;

    int count;

    void Start()
    {
        SceneManager.scene = "Tiro";

        alvo = new GameObject("Alvo", typeof(Tiro_Alvo));
        player = new GameObject("Player", typeof(Tiro_Player));
        mao = new GameObject("Mao", typeof(Tiro_Mao));

        win = 0;
        pontos = 0;
        count = 0;

        TextStyle = new GUIStyle();
        TextStyle.normal.textColor = Color.black;

        audio_s = (AudioSource)gameObject.AddComponent("AudioSource");
        audio_c = (AudioClip)Resources.Load("Sound/Tiro");
        audio_s.clip = audio_c;
        audio_s.loop = true;
    }


    void Update()
    {
        count++;

        if (Input.GetMouseButtonDown(0))
        {
            //quant_shot += 1;
            audio_s.Play();
        }

        if (Input.GetMouseButtonUp(0))
        {
            audio_s.loop = false;
        }

        if (player.transform.localPosition.x <= 0.7f &&
                player.transform.localPosition.x >= -0.5 &&
                    player.transform.localPosition.y <= 0.7f &&
                        player.transform.localPosition.y >= -0.5f && colidindo == true &&
                            Input.GetMouseButtonDown(0))
        {
            pontos += 10;
            Debug.Log("10 pontos");
        }

        else if (player.transform.localPosition.x <= 1.5f &&
                player.transform.localPosition.x >= -1.2f &&
                    player.transform.localPosition.y <= 1.5f &&
                        player.transform.localPosition.y >= -1.3f && colidindo == true &&
                            Input.GetMouseButtonDown(0))
        {
            pontos += 8;
            Debug.Log("8 pontos");
        }

        else if (player.transform.localPosition.x <= 2.2f &&
                player.transform.localPosition.x >= -1.8f &&
                    player.transform.localPosition.y <= 2.2f &&
                        player.transform.localPosition.y >= -1.9f && colidindo == true &&
                            Input.GetMouseButtonDown(0))
        {
            pontos += 5;
            Debug.Log("5 pontos");
        }


        else if (player.transform.localPosition.x <= 2.88f &&
                player.transform.localPosition.x >= -2.7f &&
                    player.transform.localPosition.y <= 2.8f &&
                        player.transform.localPosition.y >= -2.5f && colidindo == true &&
                            Input.GetMouseButtonDown(0))
        {
            pontos += 2;
            Debug.Log("2 pontos");
        }

        else
        {
            Debug.Log("Nada de ponto");
        }

        if (pontos > 100 && count < 700)
        {
            win = 1;
            SceneManager.Change();
        }
        else if (pontos < 100 && count > 700)
        {
            win -= 1;
            SceneManager.Change();
        }
    }

    void OnGUI()
    {
        GUI.Label(new Rect(Screen.width / 14, Screen.height / 7, Screen.width / 10, Screen.height / 12), "Pontos : " + pontos, TextStyle);
    }
}